f.close()
except:
pass
- XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
- cmd = "xenstored --pid-file /var/run/xenstore.pid"
- if XENSTORED_TRACE:
- cmd += " -T /var/log/xen/xenstored-trace.log"
- s,o = commands.getstatusoutput(cmd)
+ args = ['xenstored', "--pid-file", pidfname]
+ if os.getenv("XENSTORED_TRACE"):
+ args.extend(["-T", "/var/log/xen/xenstored-trace.log"])
+ pid = os.fork()
+ if pid == 0:
+ os.execvp('xenstored', args)
+ p, status = os.waitpid(pid, 0)
+ if os.WIFEXITED(status):
+ status = os.WEXITSTATUS(status)
+ if status:
+ raise RuntimeError("Failed to start xenstored: %d" % status)
def start_consoled():
if os.fork() == 0:
}
}
- if (dofork) {
- openlog("xenstored", 0, LOG_DAEMON);
- daemonize();
- }
- if (pidfile)
- write_pidfile(pidfile);
-
/* Talloc leak reports go to stderr, which is closed if we fork. */
if (!dofork)
talloc_enable_leak_report_full();
/* Restore existing connections. */
restore_existing_connections();
- if (outputpid) {
- printf("%ld\n", (long)getpid());
- fflush(stdout);
- }
-
/* redirect to /dev/null now we're ready to accept connections */
if (dofork) {
int devnull = open("/dev/null", O_RDWR);
if (devnull == -1)
barf_perror("Could not open /dev/null\n");
+
+ openlog("xenstored", 0, LOG_DAEMON);
+
+ daemonize();
+
+ if (outputpid) {
+ printf("%ld\n", (long)getpid());
+ fflush(stdout);
+ }
+
dup2(devnull, STDIN_FILENO);
dup2(devnull, STDOUT_FILENO);
dup2(devnull, STDERR_FILENO);
xprintf = trace;
}
+ if (pidfile)
+ write_pidfile(pidfile);
+
signal(SIGHUP, trigger_reopen_log);
if (xce_handle != -1)